package gpl.pierrick.brihaye.aramorph;

import gpl.pierrick.brihaye.aramorph.lucene.ArabicNormalizer;

import java.util.HashSet;
import java.util.Set;

/**
 * A dictionary that uses JDBC to get entries. It also stores all entries in
 * memory to check whether it is found or not.
 * 
 * @author Ahmed Saad, 2006
 */
public class JDBCMemDictionary extends JDBCDictionary {
	/** A set of all entries in this dictionary */
	protected Set<String> entries;

	/** A set of all normalized entries in this dictionary */
	protected Set<String> normalized_entries;

	public JDBCMemDictionary(String dictName, boolean dictionaryNormalized) {
		super(dictName, dictionaryNormalized);
		entries = new HashSet<String>();
		normalized_entries = new HashSet<String>();
		super.readonlyManager.getAllEntries(super.dictName, this.entries,
				this.normalized_entries);
	}

	@Override
	public boolean contains(String entry) {
		if (super.isDictionaryNormalized()) {
			entry = ArabicNormalizer.normalize(entry);
			if (entry == null)
				entry = "";
		}
			
		return super.isDictionaryNormalized() ? this.normalized_entries
				.contains(entry) : this.entries.contains(entry);
	}

	
}
